************************************************************
* 

clear
set more off 

***********************************************************
** Change the directory
* Radhika Nagesh
cd "C:\Users\Radhika Nagesh\Dropbox\IPA\Evaluating Civic Education Programs\Data"


// Setting globals
global rawdo = "02_cleaningdo\00_raw"
global cleando = "02_cleaningdo\01_cleaning"
global rawdata = "01_rawdata\01_surveys"
global cleandata = "03_cleandata\01_surveys"
global checks = "04_output\00_checks\round1"
global tracking = "01_rawdata\00_tracking"

global date = c(current_date)

local unique "participant_id" 	// Unique ID variable  
local enum "surveyor_id" 	// Enumerator code variable 

cap log close

*==========================================================================
*************************** Endline Survey ********************************
*==========================================================================
use "$cleandata\clean_endline_fin.dta", clear
cap drop _merge dup*

**********************
* Treatment variable *
* Introducing a new variable "trt_updated", = 1 when speakers were working, 0 when they weren't
**********************
gen trt_updated = 1
replace trt_updated = 0 if eldate == 21946 | eldate == 21947
la def spkr 1 "Valid treatment" 0 "Invalid treatment"
la var trt_updated "Treatment - Updated"
la val trt_updated spkr

tab participant_id if trt_upda == 0

// Woud you attend a peaceful protest or demonstration march?
gen protest_endline = 0
replace protest_endline=1 if repeat_peaceful==1 //Nos and maybes coded as No
la var protest_endline "Attend a peaceful protest"
la def yesno 1 "Yes" 0 "No"
la val protest_endline yesno

//If elections were held tomorrow, would you vote?
gen vote_endline = 0
replace vote_endline = 1 if repeat_voting==1
la var vote_endline "Vote in elections tomorrow"
la val vote_endline yesno

// Would you contact a govt official?
gen contactgovt_endline=0
replace contactgovt_endline=1 if repeat_govt==1
la var contactgovt "Contact a govt official"
la val contactgovt yesno

* Keeping original variables, renames as endline
rename repeat_peaceful endline_peaceful
rename repeat_voting endline_voting
rename repeat_govt endline_govt

// General outcome variables
// How interested would you say you are in politics?
recode participant_interest (1=4) (2=3) (3=2) (4=1), gen(polinterest_endline) //now 1 is not at all, 2 is not very, 3 is somewhat, and 4 is very; modes are 2 and 4
la var polinterest "Interested in politics"
la def int 1 "Not at all" 2 "Not very" 3 "Somewhat" 4 "Very"
la val polinterest int

gen pol_veryinterested_endline=0
replace pol_veryinterested_endline=1 if polinterest==4

// Do you agree or disagree - Sometimes politics and government seem so complicated for me to understand
replace pol_compli = . if pol_complic == 5
recode pol_complic (1=4) (2=2) (3=3) (4=1), gen(polefficacy_internal)
la def compl 1 "Strongly disagree" 2 "Disagree" 3 "Agree" 4 "Strongly agree"
la val poleffi compl
la var poleffica "Political Efficacy - Internal"

// Do you agree or disagree- Govt officials don't care what people like me think
replace pol_care = . if pol_care == 5 
recode pol_care (1=4) (2=2) (3=3) (4=1), gen(polefficacy_external)
la val polefficacy_external compl
la var polefficacy_external "Political Efficacy - External"

// would you attend a community meeting?
gen attendmeeting_endline=0
replace attendmeeting_endline=1 if action_meeting==1
la val attendmee yesno
la var attendmeeting_endline "Would attend Community Meeting"
//note: 97% of respondents said they would attend a community meeting

// would you attend a violent protest?
gen violentprotest_endline=0
replace violentprotest_endline=1 if action_protest==1
la val violentpro yesno
la var violentpr "Would attend Violent Protest"


// how much do you personally fear becoming a victim of political intimidation or violence?
recode pol_intimidation (1=4) (2=3) (3=2) (4=1), gen(electoralviolence)
la def intim 1 "Not at all" 2 "Not a lot" 3 "Some" 4 "A lot"
la val electoralv intim
la var electoralv "Degree of fear of facing political violence"

gen electoralviolence_alot=0
replace electoralviolence_alot=1 if electoralviolence==4

// (1) The use of violence is never justified in Zambian politics today. OR 
// (2) In this country, it is sometimes necessary to use violence in support of a just cause.
gen violencesometimesnecessary=0
replace violencesometimesnecessary=1 if pol_violence==2
la var violencesome "Violence sometimes necessary to support just cause"
la val violencesome yesno

gen violenceneverjustified=0
replace violenceneverjustified=1 if pol_violence==1
la var violencenever "Violence never justified in politics"
la val violencenever yesno

// Case study set
// Is this person's decision justified
recode case_decision (1=4) (2=3) (3=2) (4=1), gen(assessdecision)
la def dec 1 "Totally unjustified" 2 "Mostly unjustified" 3 "Mostly justified" 4 "Totally justified"
la val assessdec dec
la var assessdecision "Is the person justified in not voting"

gen totallyunjustified=0
replace totallyunjustified=1 if assessdecision==1

//  is this person a good citizen?
gen badcitizen=0
replace badcitizen=1 if case_goodcit==3
/*note: 90% of respondents said the person was not a good citizen and that voting is fundamental responsibility*/
la val badciti yesno
la var badciti "Bad citizen for not voting"

// Is this person a good christian
gen badchristian=0
replace badchristian=1 if case_goodchrist==0
la var badchr "Bad Christian for not voting"
la val badchr yesno

//does this person's decision not to vote affect their standing in the eyes of God?
rename case_god lowerstanding_god
la var lowerstan "Lower standing with God for not voting"

// Ending set
// Democracy qualiy in Zambia
recode dem_quality (1=5) (2=4) (3=3) (4=2) (5=1), gen(dem_quality_better)
la def qua 1 "Much worse" 2 "Worse" 3 "The same" 4 "Better" 5 "Much better" 
la var dem_quality_better "Quality of democracy compared to 10 yrs ago"
la val dem_quality_better qua

gen dem_quality_better_bin=0
replace dem_quality_better_bin=1 if dem_quality_better==5 | dem_quality_better==4
la var dem_quality_better_bin "Is democracy better than 10 yrs ago"
la val dem_quality_better_bin yesno

// Will you share information that you learned here today with someone who did not attend a workshop?
gen willshare=.
replace willshare=1 if info_share==2
replace willshare=0 if info_share==1 | info_share==0
la val willsha yesno
la var willshare "Will share workshop content" 

// Donation Amount
rename beh_donaton donationamount
la var donationamoun "Donation Amount"

la var site_id "Site ID"

//Donation
gen donated=.
replace donated=0 if donationamount==0
replace donated=1 if donationamount>0 & donationamount~=.
la var donated "Donation for election observation"
la val donated yesno

gen recruit = .
replace recruit = 1 if rec_type == 4
replace recruit = 2 if rec_type == 1 | rec_type == 2 | rec_type== 3 | rec_type == 5
la var recruit "Recruitment type"
la def recr 1 "Street recruitment" 2 "Church recruitment"
la val recruit recr

save "$cleandata\vars_endline_cRN.dta", replace


*==========================================================================
*************************** Baseline Survey ********************************
*==========================================================================

use "$cleandata\clean_baseline_fin.dta", clear

**********************
* Treatment variable *
* Introducing a new variable "trt_updated", = 1 when speakers were working, 0 when they weren't
**********************
gen trt_updated = 1
replace trt_updated = 0 if bldate == 21946 | bldate == 21947
la def spkr 1 "Valid treatment" 0 "Invalid treatment"
la var trt_updated "Treatment - Updated"
la val trt_updated spkr

tab participant_id if trt_upda == 0

preserve
keep trt_upda participant_id 
keep if trt_upda == 0
tempfile trt_invalid
save `trt_invalid', replace
restore

gen english=.
replace english=1 if participant_lang==0
replace english=0 if participant_lang==1 | participant_lang==2 | participant_lang==3 | participant_lang==4
la var english "Language: English"
la val english yesno

gen nyanja=.
replace nyanja=1 if participant_lang==1
replace nyanja=0 if participant_lang==0 | participant_lang==2 | participant_lang==3 | participant_lang==4
la var nyanja "Language: Nyanja"
la val nyanja yesno

gen bemba=.
replace bemba=1 if participant_lang==2
replace bemba=0 if participant_lang==0 | participant_lang==1 | participant_lang==3 | participant_lang==4
la var bemba "Language: Bemba"
la val bemba yesno

gen otherlang=.
replace otherlang=1 if participant_lang==3 | participant_lang==4
replace otherlang=0 if participant_lang==0 | participant_lang==1 | participant_lang==2 
la var otherla "Language: Other"
la val otherla yesno

rename participant_age age
la var age "Age"

rename participant_marital married
la var married "Marital Status"

rename participant_child numchildren
la var numc "Number of children"

rename female_list gender
la def gend 0 "Male" 1 "Female"
la val gender gend
la var gender "Gender"

gen educationlevel=.
replace educationlevel=participant_educ if participant_educ==0 | participant_educ==1 | participant_educ==2 | participant_educ==3 | participant_educ==4
tab educationlevel, gen(educ)
la var educ1 "Educ level: No education"
rename educ1 noschooling
la var educ2 "Educ level: Primary school"
rename educ2 primaryschool
la var educ3 "Educ level: High school"
rename educ3 highschool
la var educ4 "Educ level: Graduate"
rename educ4 university
la var educ5 "Educ level: Post graduate"
rename educ5 gradschool

gen part_church = . 
replace part_church = participant_church if participant_church!=. & participant_church<=5
tab part_church, gen(church)
la var church1 "Church Affiliation: Other"
rename church1 otherchurch
la var church2 "Church Affiliation: UCZ"
rename church2 ucz
la var church3 "Church Affiliation: Catholic"
rename church3 catholic
la var church4 "Church Affiliation: Pentecostal"
rename church4 pentecostal
la var church5 "Church Affiliation: None"
rename church5 nochurch

rename participant_church_attend churchattendance 
tab churchatt, gen(attend)
la var attend1 "Attend church: daily"
rename attend1 attenddaily
la var attend2 "Attend church: 2-5 times per week"
rename attend2 attendtwiceaweek
la var attend3 "Attend church: once a week"
rename attend3 attendonceaweek
la var attend4 "Attend church: every few weeks"
rename attend4 attendeveryfewweeks
la var attend5 "Attend church: once a month"
rename attend5 attendonceamonth
la var attend6 "Attend church: once a year"
rename attend6 attenceonceayear

la var bauleni "Bauleni"
la var chawama "Chawama"
la var mtendere "Mtendere"

// How interested would you say you are in politics?
recode participant_interest (1=4) (2=3) (3=2) (4=1), gen(polinterest_endline) //now 1 is not at all, 2 is not very, 3 is somewhat, and 4 is very; modes are 2 and 4
la var polinterest "Interested in politics"
la def int 1 "Not at all" 2 "Not very" 3 "Somewhat" 4 "Very"
la val polinterest int

gen pol_veryinterested=0
replace pol_veryinterested=1 if polinterest==4

rename participant_church_leader church_leader

rename participant_bornagain bornagain_selfid

rename participant_charismatic charismatic_selfid

rename participant_pentecostal pentecostal_selfid

rename participant_evangelical evangelical_selfid

// Repeat Questions set
// Woud you attend a peaceful protest or demonstration march?
gen protest_baseline = 0
replace protest_baseline=1 if repeat_peaceful==1 //Nos and maybes coded as No
la var protest_baseline "Attend a peaceful protest"
la def yesno 1 "Yes" 0 "No"
la val protest_baseline yesno

//If elections were held tomorrow, would you vote?
gen vote_baseline = 0
replace vote_baseline = 1 if repeat_voting==1
la var vote_baseline "Vote in elections tomorrow"
la val vote_baseline yesno

// Would you contact a govt official?
gen contactgovt_baseline=0
replace contactgovt_baseline=1 if repeat_govt==1
la var contactgovt "Contact a govt official"
la val contactgovt yesno

* Keeping original variables, renames as endline
rename repeat_peaceful baseline_peaceful
rename repeat_voting baseline_voting
rename repeat_govt baseline_govt

gen recruit = .
replace recruit = 1 if rec_type == 4
replace recruit = 2 if rec_type == 1 | rec_type == 2 | rec_type== 3 | rec_type == 5
la var recruit "Recruitment type"
la def recr 1 "Street recruitment" 2 "Church recruitment"
la val recruit recr

save "$cleandata\vars_baseline_cRN.dta", replace
